﻿#include "StdAfx.h"
#include "AuthCrypt.h"
#include "AuthClient.h"
#include "RealmHandler.h"

bool initDatabase() {
	LogonDatabase = Database::IDatabase::CreateDatabase();
	return LogonDatabase->Connect(Configs::logon().getString("Database", "host"),
		Configs::logon().getString("Database", "user"),
		Configs::logon().getString("Database", "password"),
		Configs::logon().getString("Database", "database"),
		3306
	);
}

int main() {
	new Log();
	new ThreadPool();
	new RealmHandler();

	if(!initDatabase())
	{
		std::cout << "Can not connect to Database!" << std::endl;
		std::cin.get();
		return -1;
	}

	Realm rlm;
	rlm.address = Configs::logon().getString("Realm", "address");
	rlm.icon = static_cast<uint8>(Configs::logon().getInt32("Realm", "icon"));
	rlm.id = Configs::logon().getInt32("Realm", "id");
	rlm.name = Configs::logon().getString("Realm", "name");
	rlm.population = Configs::logon().getFloat("Realm", "population");
	rlm.timeZone = static_cast<uint8>(Configs::logon().getInt32("Realm", "timeZone"));
	rlm.type = static_cast<uint8>(Configs::logon().getInt32("Realm", "type"));
	sRealmHandler.addRealm(rlm);

	Realm rlm2 = rlm;
	rlm2.id = 2;
	rlm2.name = "wasd";
	sRealmHandler.addRealm(rlm2);
	new AccountMgr(LogonDatabase);

	sAccountMgr.Update();
	
	AuthClient::startNetwork();
	std::cin.get();

	AuthClient::stopNetwork();
	sThreadPool.shutdown();
}